package com.amazon.ags.client.whispersync.savedgame;

import android.util.Log;
import com.amazon.ags.client.whispersync.GameSummary;
import java.util.Date;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonSummaryMarshaller
  implements SummaryMarshaller
{
  private static final String DESCRIPTION_KEY = "Description";
  private static final String DEVICE_ID_KEY = "DeviceId";
  private static final String FEATURE_NAME = "STC";
  private static final String MD5_KEY = "MD5";
  private static final String SAVE_TIME_KEY = "SaveTime";
  private static final String TAG = "STC_" + JsonSummaryMarshaller.class.getSimpleName();
  private static final String VERSION_KEY = "Version";

  private GameSummary makeSummary(JSONObject paramJSONObject)
    throws JSONException
  {
    return new SimpleGameSummary(paramJSONObject.getString("Version"), paramJSONObject.getString("MD5"), new Date(paramJSONObject.getLong("SaveTime")), paramJSONObject.optString("Description"), paramJSONObject.optString("DeviceId"));
  }

  public final String marshal(GameSummary paramGameSummary)
  {
    if (paramGameSummary == null)
      return null;
    JSONObject localJSONObject = new JSONObject();
    try
    {
      localJSONObject.put("Version", paramGameSummary.getVersion());
      localJSONObject.put("MD5", paramGameSummary.getMd5());
      localJSONObject.put("SaveTime", paramGameSummary.getSaveDate().getTime());
      localJSONObject.put("Description", paramGameSummary.getDescription());
      localJSONObject.put("DeviceId", paramGameSummary.getDevice());
      return localJSONObject.toString();
    }
    catch (Exception localException)
    {
      Log.e(TAG, "Unable to compose JSON object for Summary:" + paramGameSummary.toString(), localException);
    }
    return null;
  }

  public final GameSummary unmarshal(String paramString)
  {
    if (paramString == null)
      return null;
    try
    {
      GameSummary localGameSummary = makeSummary(new JSONObject(paramString));
      return localGameSummary;
    }
    catch (Exception localException)
    {
      Log.e(TAG, "Invalid JSON doc for Saved Game Summary:" + paramString, localException);
    }
    return null;
  }

  public final GameSummary[] unmarshalArray(String paramString)
  {
    SimpleGameSummary[] arrayOfSimpleGameSummary;
    try
    {
      JSONArray localJSONArray = new JSONArray(paramString);
      arrayOfSimpleGameSummary = new SimpleGameSummary[localJSONArray.length()];
      for (int i = 0; i < localJSONArray.length(); i++)
        arrayOfSimpleGameSummary[i] = makeSummary(localJSONArray.getJSONObject(i));
    }
    catch (JSONException localJSONException)
    {
      Log.e(TAG, "Invalid JSON doc for Summaries List");
      arrayOfSimpleGameSummary = new SimpleGameSummary[0];
    }
    return arrayOfSimpleGameSummary;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.amazon.ags.client.whispersync.savedgame.JsonSummaryMarshaller
 * JD-Core Version:    0.6.2
 */